package first;
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.MessageConsumer;
import javax.jms.Session;
import javax.jms.TextMessage;

import org.apache.activemq.ActiveMQConnectionFactory;

public class Receiver {

	public static void main(String[] args) throws JMSException {
		
		ConnectionFactory connectionFactory = new ActiveMQConnectionFactory();
		Connection connection = connectionFactory.createConnection();
		connection.start();
		Session session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);
		Destination destination = session.createQueue("FirstQueue");
		MessageConsumer consumer = session.createConsumer(destination);
		while(true){
			
			TextMessage message = (TextMessage)consumer.receive(1000);
			if(message != null){
				
				System.out.println("收到消息：" + message.getText());
			}else{
				
				break;
			}
		}
		
		session.commit();
		connection.close();
	}
}
